<?php
class NewShopVo extends SzAbstractMySqlVo
{

    private $userId;
    private $position;
    private $buyItemList;
    private $costItemList;
    private $isBuy;

    /**
     * Initialize NewShopVo.
     *
     * @param $userId
     * @param $position
     * @param $buyItemList
     * @param $costItemList
     * @param $isBuy
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return NewShopVo
     */
    public function __construct($userId, $position, $buyItemList, $costItemList, $isBuy, $isInsert = false) {
        $this->userId = $userId;
        $this->position = $position;
        $this->buyItemList = json_decode($buyItemList, true);
        $this->costItemList = json_decode($costItemList, true);
        $this->isBuy = $isBuy;

        $this->isInsert = $isInsert;
        $this->voClassName = 'NewShopVo';
        $this->ormName = 'NewShop';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'position' => $this->getPosition(),
            'buyItemList' => ($needEncode) ? $this->getBuyItemList() : $this->getRawBuyItemList(),
            'costItemList' => ($needEncode) ? $this->getCostItemList() : $this->getRawCostItemList(),
            'isBuy' => $this->getIsBuy(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'position' => $this->getPosition(),
            'buyItemList' => ($needEncode) ? $this->getBuyItemList() : $this->getRawBuyItemList(),
            'costItemList' => ($needEncode) ? $this->getCostItemList() : $this->getRawCostItemList(),
            'isBuy' => $this->getIsBuy(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getPosition(),
            $this->getBuyItemList(),
            $this->getCostItemList(),
            $this->getIsBuy(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getPosition()
    {
        return $this->position;
    }

    public function setPosition($val)
    {
        $this->saveColumnStatus(1, $this->position);
        $this->position = $val;
    }

    public function getBuyItemList()
    {
        return json_encode($this->buyItemList);
    }

    public function getRawBuyItemList()
    {
        return $this->buyItemList;
    }

    public function setBuyItemList($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 218400) {
            SzLogger::get()->error('[NewShopVo] The length of column buyItemList exceed the limit, length / limit: ' . $encodedLength . ' / 218400');
            throw new SzException(10522, array('NewShopVo', '218400', $encodedLength));
        } else if ($encodedLength > 196560) {
            SzLogger::get()->warn('[NewShopVo] The length of column buyItemList exceed the warning level, length / limit: ' . $encodedLength . ' / 218400');
        }
        $this->saveColumnStatus(2, $this->buyItemList);
        $this->buyItemList = $val;
    }

    public function getCostItemList()
    {
        return json_encode($this->costItemList);
    }

    public function getRawCostItemList()
    {
        return $this->costItemList;
    }

    public function setCostItemList($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 218400) {
            SzLogger::get()->error('[NewShopVo] The length of column costItemList exceed the limit, length / limit: ' . $encodedLength . ' / 218400');
            throw new SzException(10522, array('NewShopVo', '218400', $encodedLength));
        } else if ($encodedLength > 196560) {
            SzLogger::get()->warn('[NewShopVo] The length of column costItemList exceed the warning level, length / limit: ' . $encodedLength . ' / 218400');
        }
        $this->saveColumnStatus(3, $this->costItemList);
        $this->costItemList = $val;
    }

    public function getIsBuy()
    {
        return $this->isBuy;
    }

    public function setIsBuy($val)
    {
        $this->saveColumnStatus(4, $this->isBuy);
        $this->isBuy = $val;
    }

}